home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE08 / DATADICT / RUNINFO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-08  |  7.2 KB  |  249 lines

  1. unit Runinfo;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Grids, Menus, StdCtrls, Buttons;
  8.  
  9. type
  10.   TRunInfoForm = class(TForm)
  11.     Memo1: TMemo;
  12.     ScrollBox1: TScrollBox;
  13.     StringGrid: TStringGrid;
  14.     MainMenu1: TMainMenu;
  15.     File1: TMenuItem;
  16.     Options1: TMenuItem;
  17.     Exit1: TMenuItem;
  18.     Options2: TMenuItem;
  19.     procedure FormCreate(Sender: TObject);
  20.     procedure UpdateInfo(const currentinfo : string);
  21.   private
  22.     fLastCol : integer;  {last col written to}
  23.     procedure AdjustColWidth(const whichcol : integer);
  24.     procedure ShowDiff(const tgtcol, tgtrow : integer);
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29. var
  30.   RunInfoForm: TRunInfoForm;
  31.  
  32.  
  33. implementation
  34. uses toolhelp, db;
  35.  
  36. {$R *.DFM}
  37. const
  38.   Uheaprow = 1;
  39.   GDIheaprow = 2;
  40.   GlbHeaprow = 3;
  41.   GlbChunkrow = 4;
  42.   {appFootPrintRow = 5;}
  43.   NumDBrow = 5;
  44.   NumTablesRow = 6;
  45.   { Heap info strings }
  46.   UHeapStr     = '%d';
  47.   GDIHeapStr   = '%d';
  48.   GlbHeapStr   = '%10.0n';
  49.   GlbCmpStr    = '%10.0n';
  50.   FootPrintStr = '%10.0n';
  51.   SessStr      = '%d';
  52.   TblsStr      = '%d';
  53. var
  54.   Info: TSysHeapInfo;
  55.  
  56. procedure TRunInfoForm.AdjustColWidth(const whichcol : integer);
  57. var i, x, biggest : integer;
  58. begin with stringgrid do begin
  59.   biggest := 0;
  60.   for i:= 0 to rowcount -1  do
  61.     if canvas.TextWidth(cells[whichCol,i]) > biggest
  62.       then biggest := canvas.textwidth(cells[WhichCol,i]);
  63.   colWidths[longint(whichCol)] := biggest+6;
  64.   end;
  65. end;
  66.  
  67.  
  68. Procedure TRunInfoForm.ShowDiff(const tgtcol, tgtrow : integer);
  69. var mostRecentCol, prevcol : integer;
  70.  
  71.   function dstrToInt(const s: string): longint;
  72.   var i : integer;
  73.       tmpstr : string;
  74.   const numeric : set of ' '..'z' = ['1', '2', '3', '4', '5', '6', '7', '8', '9','0'];
  75.   begin
  76.     tmpstr := '';
  77.     for i := 1 to length(s) do
  78.       if s[i] in numeric
  79.         then tmpstr := tmpstr + s[i];
  80.     if tmpstr = ''
  81.       then tmpstr := '0';
  82.     result := StrToInt(tmpstr);
  83.   end;
  84.  
  85. begin
  86.   {first take into account insertion of diff columns}
  87.   if tgtcol = 3
  88.     then begin
  89.       MostRecentcol := 2;
  90.       prevcol := 1;
  91.       end
  92.     else begin
  93.       MostRecentcol := tgtcol - 1;
  94.       prevCol := tgtcol - 3;
  95.       end;
  96.   with stringGrid do
  97.    cells[tgtcol,tgtrow] := intToStr( dstrToInt(cells[PrevCol,tgtrow]) - dstrToInt(cells[MostRecentCol, tgtrow]));
  98. end;
  99.  
  100. (**
  101. function GetWindowInfo(Wnd: HWnd): String;
  102. var
  103.   Caption: array[0..255] of Char;
  104.   ClassName: array[0..255] of Char;
  105.   ExeName: array[0..255] of Char;
  106.   Instance: Cardinal;
  107. const
  108.   Visibility: array[False..True] of String[8] = ('(hidden)', '');
  109. begin
  110.   GetWindowText(Wnd, Caption, SizeOf(Caption));
  111.   GetClassName(Wnd, ClassName, SizeOf(ClassName));
  112.   {$ifndef WIN32}
  113.   Instance := GetWindowWord(Wnd, gww_HInstance);
  114.   {$else}
  115.   Instance := GetWindowLong(Wnd, gwl_HInstance);
  116.   {$endif}
  117.   GetModuleFileName(Instance, ExeName, SizeOf(ExeName));
  118.   Result :=
  119.     '{' + StrPas(ClassName) + '} ' +
  120.     StrPas(ExeName) + ' "' +
  121.     StrPas(Caption) + '" ' +
  122.     Visibility[GetWindowLong(Wnd, gwl_Style) and ws_Visible <> 0];
  123. end;
  124.  
  125. function EnumChildWindowsProc(Wnd: HWnd; UserData: Longint): Bool;
  126. {$ifndef WIN32} export;{$else} stdcall;{$endif}
  127. begin
  128.   Result := True;
  129.   TOutline(UserData).Lines.Add(#32 + GetWindowInfo(Wnd));
  130. end;
  131.  
  132. function EnumWindowsProc(Wnd: HWnd; UserData: Longint): Bool;
  133. {$ifndef WIN32} export;{$else} stdcall;{$endif}
  134. begin
  135.   Result := True;
  136.   TOutline(UserData).Lines.Add(GetWindowInfo(Wnd));
  137.   EnumChildWindows(Wnd, @EnumChildWindowsProc, UserData);
  138. end;
  139. **)
  140.  
  141.  
  142. procedure TRunInfoForm.FormCreate(Sender: TObject);
  143. var
  144.   i,
  145.   biggest : integer;
  146.   bigstr,
  147.   tmpstr : string;
  148.   SearchRec : TSearchRec;
  149. begin
  150.   visible := false;
  151.   memo1.lines.clear;
  152.   memo1.lines.add('Run information for '+application.exename);
  153.   i := FindFirst(Application.exename, faAnyfile, SearchRec);
  154.   memo1.lines.add(formatDateTime('"Compiled:" dddd, mmmm d, yyyy, ' +
  155.   '"at" hh:mm AM/PM', filedateToDateTime(SearchRec.time)));
  156.   memo1.lines.add('Exe size = '+intToStr(SearchRec.size));
  157. with stringGrid do begin
  158.   cells[0,0] := ' ';
  159.   cells[0,1] := 'Heap%Free';
  160.   cells[0,2] := 'GDI%Free';
  161.   cells[0,3] := 'FreeBytes';
  162.   cells[0,4] := 'Big Chunk';
  163.   cells[0,5] := 'Num DB:';
  164.   cells[0,6] := 'Num tbls';
  165.  
  166.   { Get initial heap information }
  167.   Info.dwSize := SizeOf(TSysHeapInfo);
  168.   SystemHeapInfo(@Info);
  169.   cells[1,0] := 'Initial';
  170.   cells[01,Uheaprow] :=(Format(UHeapStr, [Info.wUserFreePercent]));
  171.   cells[01,GDiHeaprow] :=(Format(GDIHeapStr, [Info.wGDIFreePercent]));
  172.   cells[01,GlbHeaprow] :=(Format(GlbHeapStr, [1.0*GetFreeSpace(0)]));
  173.   cells[01,GlbChunkrow] :=(format(glbcmpstr, [1.0*GlobalCompact(0)]));
  174.   cells[01,NumDbrow] :=(format(sessStr, [session.databasecount]));
  175.   AdjustColWidth(0);
  176.   AdjustColWidth(1);
  177.   update;
  178.   fLastcol := 1;
  179.   end;
  180. end;
  181.  
  182.  
  183. procedure TRunInfoForm.UpdateInfo(const currentinfo : string);
  184. var
  185.   i, j,
  186.   numtables,
  187.   biggest : integer;
  188.   bigstr,
  189.   tmpstr : string;
  190.   tablelist,
  191.   sessionlist : tstrings;
  192. begin
  193.   inc(FlastCol);
  194.   with stringGrid do Begin
  195.     colcount := FlastCol + 1;
  196.     Info.dwSize := SizeOf(TSysHeapInfo);
  197.     SystemHeapInfo(@Info);
  198.     cells[FLastCol,0] := currentinfo;
  199.     cells[FLastCol, Uheaprow] :=(Format(UHeapStr, [Info.wUserFreePercent]));
  200.     cells[FLastCol, GDiHeaprow] :=(Format(GDIHeapStr, [Info.wGDIFreePercent]));
  201.     cells[FLastCol, GlbHeaprow] :=(Format(GlbHeapStr, [1.0*GetFreeSpace(0)]));
  202.     cells[FLastCol, GlbChunkrow] :=(format(glbcmpstr, [1.0*GlobalCompact(0)]));
  203.     cells[FLastCol, NumDbrow] :=(format(sessStr, [session.databasecount]));
  204.     with session do begin
  205.       sessionlist := tstringlist.create;
  206.       numtables := 0;
  207.       for i := 0 to databasecount - 1 do
  208.         begin
  209.           sessionlist.add(databases[i].name);
  210.           if databases[i].connected
  211.             then begin
  212.               sessionlist.add(' -> ' + databases[i].databasename);
  213.               tablelist := tstringlist.create;
  214.               session.getTableNames(databases[i].databasename,'*.*', true, true, tablelist);
  215.               numtables := numtables + tablelist.count;
  216.               for j := 0 to tablelist.count -1 do
  217.                   tablelist.strings[j] := ' tbl: '+ tablelist.strings[j];
  218.               sessionlist.addStrings(tablelist);
  219.               tablelist.free;
  220.               end;
  221.           end;
  222.       cells[FLastCol, NumTablesRow] := format(tblsStr, [numtables]);
  223.       if rowcount < NumTablesRow + sessionList.count +1
  224.         then rowcount := NumTablesRow + sessionList.count + 1;
  225.       for i := 0 to sessionlist.count -1 do
  226.         cells[FlastCol, NumTablesRow+1+i] := sessionlist.strings[i];
  227.       sessionList.free;
  228.       end;  { with session}
  229.     inc(FlastCol);
  230.     colcount := FlastCol + 1;
  231.     cells[FlastCol, 0] := 'used';
  232.     ShowDiff(FLastCol, Uheaprow);
  233.     ShowDiff(FLastCol, GDiHeaprow);
  234.     ShowDiff(FLastCol, GlbHeaprow);
  235.     ShowDiff(FLastCol, GlbChunkrow);
  236.     ShowDiff(FLastCol, NumDbrow);
  237.     ShowDiff(FlastCol, NumTablesRow);
  238.     AdjustColWidth(FLastCol-1);
  239.     AdjustColWidth(FLastCol);
  240.     update;
  241.     end;
  242. end;
  243.  
  244. Initialization
  245.  
  246. RunInfoForm := TrunInfoForm.create(application);
  247.  
  248. end.
  249.